package com.shrcl.engineerprocess.domain.impl;

import com.shrcl.engineerprocess.domain.Engineer;
import com.shrcl.engineerprocess.domain.EngineerNotifyReceiver;
import com.shrcl.engineerprocess.domain.EngineerTraining;
import com.shrcl.engineerprocess.domain.NotificationSender;
import com.shrcl.engineerprocess.domain.TrainingNotification;
import com.shrcl.engineerprocess.domain.impl.EngineerImpl;
import com.shrcl.engineerprocess.domain.impl.EngineerTrainingImpl;
import com.shrcl.engineerprocess.domain.impl.NotificationImpl;
import com.shrcl.engineerprocess.domain.proxy.TrainingNotificationProxy;
import edu.fudan.mylang.pf.IObjectFactory;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import org.eclipse.xtext.xbase.lib.InputOutput;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.springframework.beans.factory.BeanFactory;

@Entity
@DiscriminatorValue("TRAININGNOTIFICATION_TYPE")
public class TrainingNotificationImpl extends NotificationImpl implements TrainingNotification {
  public TrainingNotificationImpl() {
    super();
  }
  
  @JoinColumn(name = "engineerTraining_id")
  @ManyToOne(targetEntity = EngineerTrainingImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private EngineerTraining engineerTraining;
  
  public EngineerTraining getEngineerTraining() {
    return this.engineerTraining;
  }
  
  public TrainingNotification setEngineerTraining(final EngineerTraining engineerTraining) {
    this.engineerTraining = engineerTraining;
    return this;			
    
  }
  
  @JoinColumn(name = "toEngineer_id")
  @ManyToOne(targetEntity = EngineerImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private Engineer toEngineer;
  
  public Engineer getToEngineer() {
    return this.toEngineer;
  }
  
  public TrainingNotification setToEngineer(final Engineer toEngineer) {
    this.toEngineer = toEngineer;
    return this;			
    
  }
  
  public void doNotify() {
    InputOutput.<String>println("============>send TrainingNotification invoke");
    EngineerNotifyReceiver _asNotifyReceiver = this.toEngineer.asNotifyReceiver();
    this.setReceiver(_asNotifyReceiver);
    BeanFactory _beanFactory = this.getBeanFactory();
    final NotificationSender notificationSender = _beanFactory.<NotificationSender>getBean(NotificationSender.class);
    notificationSender.sendNotification(this);
  }
  
  public void init() {
    this.setNotificationType("TrainingNotification");
  }
  
  public static TrainingNotification create(final IObjectFactory objectFactory) {
    com.shrcl.engineerprocess.domain.TrainingNotification trainingNotification = new com.shrcl.engineerprocess.domain.impl.TrainingNotificationImpl(
    );
    objectFactory.create(trainingNotification);
    return trainingNotification;			
    
  }
  
  public static TrainingNotification createTrainingNotificationImpl(final IObjectFactory objectFactory, final Procedure1<TrainingNotification> init) {
    com.shrcl.engineerprocess.domain.TrainingNotification trainingNotification = new com.shrcl.engineerprocess.domain.impl.TrainingNotificationImpl(
    );
    objectFactory.create(trainingNotification);
    init.apply(trainingNotification);
    
    return trainingNotification;			
    
  }
  
  public TrainingNotificationProxy toProxy() {
    com.shrcl.engineerprocess.domain.proxy.TrainingNotificationProxy proxy = new com.shrcl.engineerprocess.domain.proxy.TrainingNotificationProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
